package com.liujun.spring4.demo.aop.aop.methodInterceptor;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * 使用环绕增强进行横切逻辑
 *
 * 环绕增强允许在目标类的方法调用前后织入逻辑，它综合实现了前置，后置的功能
 *
 * @author liujun
 * @version 0.0.1
 * @date 2018/09/22
 */
public class GreetingInterceptor implements MethodInterceptor {

  @Override
  public Object invoke(MethodInvocation invocation) throws Throwable {

    Object[] args = invocation.getArguments();

    String clientName = String.valueOf(args[0]);

    System.out.println("How are you Mr." + clientName);

    Object obj = invocation.proceed();

    System.out.println("please enjoy youself !");

    return obj;
  }
}
